package com.edata.bigdata.nebulasource

import org.apache.log4j.Logger

class NebulaConnConfig extends Serializable {
  @transient lazy val LOGGER = Logger.getLogger(this.getClass)
  var graph_addr = "127.0.0.1:9669"
  var graph_ssl = false
  var meta_addr = "127.0.0.1:9559"
  var meta_ssl = false
  var user = "root"
  var password = "123"
  var conn_timeout = 60000
  var conn_retry = 2


  def builder(): NebulaConnConfig = {
    new NebulaConnConfig()
  }

  def withGraphAddr(addr: String): NebulaConnConfig = {
    this.graph_addr = addr
    this
  }

  def withGraphSSL(enable: Boolean): NebulaConnConfig = {
    this.graph_ssl = enable
    this
  }

  def withMetaAddr(addr: String): NebulaConnConfig = {
    this.meta_addr = addr
    this
  }

  def withMetaSSL(enable: Boolean): NebulaConnConfig = {
    this.meta_ssl = enable
    this
  }

  def withUser(user: String): NebulaConnConfig = {
    this.user = user
    this
  }

  def withPassword(password: String): NebulaConnConfig = {
    this.password = password
    this
  }

  def withConnTimeout(timeout: Int): NebulaConnConfig = {
    this.conn_timeout = timeout
    this
  }

  def withConnRetry(num: Int): NebulaConnConfig = {
    this.conn_retry = num
    this
  }

  def build(): NebulaConnConfig = {
    check()
    this
  }

  def check(): Unit = {
    assert(this.graph_addr != null && !this.graph_addr.isEmpty, "graph address is empty")
    assert(this.conn_timeout > 0, "timeout must be larger than 0")
    assert(this.conn_retry > 0, "retry must be larger than 0")
  }


}

object NebulaConnConfig {
  def builder(): NebulaConnConfig = {
    new NebulaConnConfig
  }


}
